import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.vfs.VirtualFile;

import java.io.IOException;

public class openClassRight extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
        String parentPath = virtualFile.getParent().getPath();
        String opendDir = parentPath.replace("src/main/java", "target/classes");
        try {
            String osName = System.getProperty("os.name");
            if (osName != null) {
                if (osName.contains("Mac")) {
                    Runtime.getRuntime().exec("open " + opendDir);
                } else if (osName.contains("Windows")) {
                    Runtime.getRuntime().exec("cmd /c start " + opendDir);
                } else {
                    System.out.println("未知系统");
                }
            }
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
    }
}
